// Copyright (c) 2023 CHANGLEI. All rights reserved.

import 'package:flutter/services.dart';
import 'package:tverify/src/ui_decorator.dart';
import 'package:tverify/tverify_platform_interface.dart';

export 'package:tverify/src/ui_decorator.dart' hide DecoratorCallbacks;
export 'package:tverify/src/ui_view.dart';

/// Created by changlei on 2023/8/14.
///
/// 腾讯一键登录sdk
class Tverify {
  const Tverify._();

  /// 初始化
  static Future<void> initLogin(String appId) {
    return TverifyPlatform.instance.initLogin(appId);
  }

  /// 预登录
  static Future<Map<String, dynamic>?> preLogin() {
    return TverifyPlatform.instance.preLogin();
  }

  /// 登录
  static Future<Map<String, dynamic>?> login(UIDecorator decorator) {
    return TverifyPlatform.instance.login(decorator);
  }

  /// networkType 类型NSString
  /// 值 == 0.无网络; 1.数据流量; 2.wifi; 3.数据+wifi
  /// carrier 类型NSNumber
  /// 值 == 0.未知(未插sim卡，其它运营商等); 1.中国移动mobile;2.中国联通unicom;3.中国电信telecom
  /// iOS only
  static Future<Map<String, dynamic>?> getSimInfo() {
    return TverifyPlatform.instance.getSimInfo();
  }

  /// 删除取号缓存数据 + 重置网络开关（自定义按钮事件里dimiss授权界面需调用）
  static Future<bool?> deleteScrip() {
    return TverifyPlatform.instance.deleteScrip();
  }

  /// 设置超时
  /// 设置取号、授权请求和本机号码校验请求时的超时时间，开发者不配置时，默认所有请求的超时时间都为8000，单位毫秒
  static Future<void> setTimeout(Duration duration) {
    return TverifyPlatform.instance.setTimeout(duration);
  }

  /// 关闭授权界面
  static Future<void> dismissLogin([bool animated = true]) {
    return TverifyPlatform.instance.dismissLogin(animated);
  }

  /// 获取网络类型，Android only
  static Future<String?> getNetworkType() {
    return TverifyPlatform.instance.getNetworkType();
  }

  /// 获取网络类型，Android only
  static Future<String?> getOperatorType() {
    return TverifyPlatform.instance.getOperatorType();
  }

  /// 验证手机号，Android only
  static Future<void> certificationNumber(String number) {
    return TverifyPlatform.instance.certificationNumber(number);
  }

  /// 设置debug模式，Android only
  static Future<void> setDebugModel(bool isDebug) {
    return TverifyPlatform.instance.setDebugModel(isDebug);
  }

  /// 设置登录按钮文字，Android only
  static Future<void> setLoginBtn(String text) {
    return TverifyPlatform.instance.setLoginBtn(text);
  }

  /// 设置是否回调，Android only
  static Future<void> setSecondPrivacyCallback(bool isCallback) {
    return TverifyPlatform.instance.setSecondPrivacyCallback(isCallback);
  }

  /// checkbox选中事件，Android only
  static void addCheckboxCheckedListener(ValueChanged<Map<String, dynamic>?> callback) {
    TverifyPlatform.instance.addCheckboxCheckedListener(callback);
  }

  /// 点击登录按钮，Android only
  static void addLoginClickCompleteListener(ValueChanged<Map<String, dynamic>?> callback) {
    TverifyPlatform.instance.addLoginClickCompleteListener(callback);
  }

  /// 开始点击登录按钮，Android only
  static void addLoginClickStartListener(ValueChanged<Map<String, dynamic>?> callback) {
    TverifyPlatform.instance.addLoginClickStartListener(callback);
  }

  /// checkbox选中事件变更，Android only
  static void addCheckboxCheckedChangeListener(ValueChanged<bool> callback) {
    TverifyPlatform.instance.addCheckboxCheckedChangeListener(callback);
  }

  /// 授权登录，Android only
  static void addAuthLoginListener(VoidCallback callback) {
    TverifyPlatform.instance.addAuthLoginListener(callback);
  }

  /// 点击返回按钮，Android only
  static void addPressBackListener(VoidCallback callback) {
    TverifyPlatform.instance.addPressBackListener(callback);
  }

  /// checkbox选中事件，Android only
  static void removeCheckboxCheckedListener(ValueChanged<Map<String, dynamic>?> callback) {
    TverifyPlatform.instance.removeCheckboxCheckedListener(callback);
  }

  /// 点击登录按钮，Android only
  static void removeLoginClickCompleteListener(ValueChanged<Map<String, dynamic>?> callback) {
    TverifyPlatform.instance.removeLoginClickCompleteListener(callback);
  }

  /// 开始点击登录按钮，Android only
  static void removeLoginClickStartListener(ValueChanged<Map<String, dynamic>?> callback) {
    TverifyPlatform.instance.removeLoginClickStartListener(callback);
  }

  /// checkbox选中事件变更，Android only
  static void removeCheckboxCheckedChangeListener(ValueChanged<bool> callback) {
    TverifyPlatform.instance.removeCheckboxCheckedChangeListener(callback);
  }

  /// 授权登录，Android only
  static void removeAuthLoginListener(VoidCallback callback) {
    TverifyPlatform.instance.removeAuthLoginListener(callback);
  }

  /// 点击返回按钮，Android only
  static void removePressBackListener(VoidCallback callback) {
    TverifyPlatform.instance.removePressBackListener(callback);
  }
}
